package exif;

import java.io.File;
import java.io.IOException;

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.xmp.XmpDescriptor;
import com.drew.metadata.xmp.XmpDirectory;

public class TagGrabber {

	public TagGrabber() {
	}

	public static void main(String[] args) {
		try {
			Metadata metadata = ImageMetadataReader.readMetadata(new File("33891045_p12.jpg"));
			XmpDirectory xmpDir = metadata.getDirectory(XmpDirectory.class);
			System.out.println("rating "+xmpDir.getString(XmpDirectory.TAG_RATING));
			Directory d3 = metadata.getDirectory(ExifIFD0Directory.class);
			for(Directory d : metadata.getDirectories()) {
				System.out.println("directory "+d.getName()+" with "+d.getTagCount()+" tags");
				for(Tag t: d.getTags()) {
					System.out.println("name "+t.getTagName());
					System.out.println("desc "+t);
				}
			}
		} catch (ImageProcessingException | IOException e) {
			e.printStackTrace();
		}
	}

}
